package com.jiutianniao.p2p.acctrans.core.account.impl;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.jiutianniao.p2p.acctrans.core.account.Account;
import com.jiutianniao.p2p.acctrans.core.account.AccountFactory;
import com.jiutianniao.p2p.acctrans.core.dal.model.AccountDO;
import com.jiutianniao.p2p.acctrans.core.exception.TransException;
import com.jiutianniao.p2p.acctrans.core.service.ServiceBeans;
import com.jiutianniao.p2p.acctrans.core.vo.LockAccountVO;
import com.jiutianniao.p2p.trans.client.enums.TransResultEnum;

@Service("accountFactory")
public class AccountFactoryImpl implements AccountFactory {

	@Resource
	private ServiceBeans serviceBeans;

	@Override
	public Account getAccount(LockAccountVO lockAccountVO)
			throws TransException {

		Account account = new StandardAccount();
		((StandardAccount) account).setServiceBeans(serviceBeans);
		((StandardAccount) account).setAction(lockAccountVO.getAction());
		AccountDO accountDO = serviceBeans.getAccountService().selectForLock(
				lockAccountVO.getAccountNo());
		if (accountDO == null) {
			throw new TransException(TransResultEnum.account_exist_error);
		}
		((StandardAccount) account).setAccountDO(accountDO);
		return account;

	}

}
